clear all 
set more off

cd "C:\Dropbox\Average_target_survey\replication_folder\rawdata"

import excel using "survey_data_2020_09_01_for_STATA.xlsx", sheet("survey_data_2020_09_01") cellrange("A3") firstrow clear

*===============================================================================
*				destring variables
*===============================================================================
foreach var in Q2 Q3 Q48 Q49 Q124 Q51 Q52 Q1341 QA11 Q111 Q151 ///
	QJH2 QJH3 QJH4 QJH6 QJH13 QJH14 QJH15 QJH16 ///
	Q27 Q53 Q121 FL_5_DO ///
	QJH1_DO QJH5_DO QJH8_DO QJH9_DO  ///
	FL_37_DO FL_38_DO  {
		encode `var', gen(`var'N)
		drop `var'
		rename `var'N `var'
	}
	
*** zipcode	
replace Q50="32259" if Q50=="32259-8302"
replace Q50="91913" if Q50=="91913-3329"
replace Q50="50316" if Q50=="50316-3960"
replace Q50="55303" if Q50=="55303-2080"

destring Q50, force replace

*** fix labels for how many times people heard about the Fed	
label define many_news ///
	1 "Just one" ///
	2 "2" ///
	3 "3 to 5" ///
	4 "5+" ///
	5 "I don't remember" 

recode QJH4 1=5 2=1 3=4 4=3  5=2

						 
*** fix labels for when people heard the newspapers
label define when_hear ///
	0 "In the last couple of hours" ///
	1 "Earlier today" ///
	2 "Yesterday" ///
	3 "Two days ago" ///
	4 "Three days ago" ///
	5 "More than three days ago" ///
	6 "I don't remember"
recode QJH6 3=0  7=2 6=3 5=4 4=5 2=6
label values QJH6 	when_hear
	
*** fix labels for when people think mortgage rates will increase
label define when_mrt ///
	0 "Second half of 2020" ///
	1 "First half of 2021" ///
	2 "Second half of 2021" ///
	3 "Sometime in 2022" ///
	4 "Sometime in 2023" ///
	5 "In 2024 or later" ///
	6 "They are unlikely to rise" ///
	99 "Not sure"
recode QJH16 3=99 4=0 1=1 6=3 8=6 5=2  7=4 2=5 
label values QJH16 when_mrt					   
						   
*** fix labels for income
label define inc_bin ///
	0 "Less than $10,000" ///
	1 "$10,000 - $19,999" ///
	2 "$20,000 - $34,999" ///
	3 "$35,000 - $49,999" ///
	4 "$50,000 - $99,999" ///
	5 "$100,000 - $199,999" ///
	6 "More than $200,000" 
recode Q49 6=0 1=1 3=2 4=3 5=4 2=5 7=6
label values Q49 inc_bin	
	   

*** fix labels for education (make sequential)
label define inc_edu ///
	1 "Less than high school" ///
	2 "High school diploma or equivalent" ///
	3 "Some college, but no degree" ///
	4 "Bachelor's degree" ///
	5 "Master's degree" ///
	6 "Doctorate or Professional Degree" 
recode Q48 1=4 2=6 3=2 4=1 5=5 6=3
label values Q48 inc_edu	  
					 
*===============================================================================
*				code variables with multiple options allowed
*===============================================================================

* QJH1

gen QJH1_1=0 if QJH1~=""
replace QJH1_1=1 if strpos(QJH1,"Articles in either general-interest newspapers or specialized economics and finance newspapers")~=0 & QJH1~="" 

gen QJH1_2=0 if QJH1~=""
replace QJH1_2=1 if strpos(QJH1,"online or in print (like the USA Today, New York Times, Wall Street Journal, Economist)")~=0 & QJH1~="" 

gen QJH1_3=0 if QJH1~=""
replace QJH1_3=1 if strpos(QJH1,"Twitter, Facebook, or other social media")~=0 & QJH1~="" 

gen QJH1_4=0 if QJH1~=""
replace QJH1_4=1 if strpos(QJH1,"News or other programs on television and radio")~=0 & QJH1~="" 

gen QJH1_5=0 if QJH1~=""
replace QJH1_5=1 if strpos(QJH1,"Other internet sources (blogs, discussion forums)")~=0 & QJH1~="" 

gen QJH1_6=0 if QJH1~=""
replace QJH1_6=1 if strpos(QJH1,"Coworkers")~=0 & QJH1~="" 

gen QJH1_7=0 if QJH1~=""
replace QJH1_7=1 if strpos(QJH1,"Friends and relatives")~=0 & QJH1~="" 

gen QJH1_8=0 if QJH1~=""
replace QJH1_8=1 if strpos(QJH1,"I did not come across any information on economic and business conditions")~=0 & QJH1~="" 

gen QJH1_9=0 if QJH1~=""
replace QJH1_9=1 if strpos(QJH1,"Official sources (like the web pages of the government, statistical agencies, or the Federal Reserve Banks)")~=0 & QJH1~="" 

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* QJH5

gen QJH5_1=0 if QJH5~=""
replace QJH5_1=1 if strpos(QJH5,"Articles in either general-interest newspapers or specialized economics and finance newspapers")~=0 & QJH5~="" 
label var QJH5_1 "Heard about Fed from: Articles in either general-interest"

gen QJH5_2=0 if QJH5~=""
replace QJH5_2=1 if strpos(QJH5,"online or in print (like the USA Today, New York Times, Wall Street Journal, Economist)")~=0 & QJH5~="" 
label var QJH5_2 "Heard about Fed from: online or in print"

gen QJH5_3=0 if QJH5~=""
replace QJH5_3=1 if strpos(QJH5,"Twitter, Facebook, or other social media")~=0 & QJH5~="" 
label var QJH5_3 "Heard about Fed from: Twitter, Facebook"

gen QJH5_4=0 if QJH5~=""
replace QJH5_4=1 if strpos(QJH5,"News or other programs on television and radio")~=0 & QJH5~="" 
label var QJH5_4 "Heard about Fed from: News or other programs on television and radio"

gen QJH5_5=0 if QJH5~=""
replace QJH5_5=1 if strpos(QJH5,"Other internet sources (blogs, discussion forums)")~=0 & QJH5~="" 
label var QJH5_5 "Heard about Fed from: Other internet sources"

gen QJH5_6=0 if QJH5~=""
replace QJH5_6=1 if strpos(QJH5,"Coworkers")~=0 & QJH5~="" 
label var QJH5_6 "Heard about Fed from: Coworkers"

gen QJH5_7=0 if QJH5~=""
replace QJH5_7=1 if strpos(QJH5,"Friends and relatives")~=0 & QJH5~="" 
label var QJH5_7 "Heard about Fed from: Friends and relatives"

gen QJH5_8=0 if QJH5~=""
replace QJH5_8=1 if strpos(QJH5,"I did not come across any information on economic and business conditions")~=0 & QJH5~="" 
label var QJH5_8 "Heard about Fed from: I did not come across"

gen QJH5_9=0 if QJH5~=""
replace QJH5_9=1 if strpos(QJH5,"Official sources (like the web pages of the government, statistical agencies, or the Federal Reserve Banks)")~=0 & QJH5~="" 
label var QJH5_9 "Heard about Fed from: Official sources"
	
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* QJH8

gen QJH8_1=0 if QJH8~=""
replace QJH8_1=1 if strpos(QJH8,"Jerome Powell")~=0 & QJH8~="" 
label var QJH8_1 "Heard about Fed from: Jerome Powell"

gen QJH8_2=0 if QJH8~=""
replace QJH8_2=1 if strpos(QJH8,"Christine Lagarde")~=0 & QJH8~="" 
label var QJH8_2 "Heard about Fed from: Christine Lagarde"

gen QJH8_3=0 if QJH8~=""
replace QJH8_3=1 if strpos(QJH8,"Alan Greenspan")~=0 & QJH8~="" 
label var QJH8_3 "Heard about Fed from: Alan Greenspan"

gen QJH8_4=0 if QJH8~=""
replace QJH8_4=1 if strpos(QJH8,"Janet Yellen")~=0 & QJH8~="" 
label var QJH8_4 "Heard about Fed from: Janet Yellen"

gen QJH8_5=0 if QJH8~=""
replace QJH8_5=1 if strpos(QJH8,"None of the above")~=0 & QJH8~="" 
label var QJH8_5 "Heard about Fed from: None of the above"

gen QJH8_6=0 if QJH8~=""
replace QJH8_6=1 if strpos(QJH8,"remember")~=0 & QJH8~="" 
label var QJH8_6 "Heard about Fed from: I don’t remember their names"

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* QJH9

gen QJH9_1=0 if QJH9~=""
replace QJH9_1=1 if strpos(QJH9,"Keeping interest rates low to reduce the government")~=0 & QJH9~="" 
label var QJH9_1 "Fed objective: Keeping interest rates low to reduce the government’s cost of borrowing"

gen QJH9_2=0 if QJH9~=""
replace QJH9_2=1 if strpos(QJH9,"Promoting maximum employment")~=0 & QJH9~="" 
label var QJH9_2 "Fed objective: Promoting maximum employment"

gen QJH9_3=0 if QJH9~=""
replace QJH9_3=1 if strpos(QJH9,"Keeping stock prices high")~=0 & QJH9~="" 
label var QJH9_3 "Fed objective: Keeping stock prices high"

gen QJH9_4=0 if QJH9~=""
replace QJH9_4=1 if strpos(QJH9,"Bailing out failing financial institutions")~=0 & QJH9~="" 
label var QJH9_4 "Fed objective: Bailing out failing financial institutions"

gen QJH9_5=0 if QJH9~=""
replace QJH9_5=1 if strpos(QJH9,"Ensuring price stability")~=0 & QJH9~="" 
label var QJH9_5 "Fed objective: Ensuring price stability"

gen QJH9_6=0 if QJH9~=""
replace QJH9_6=1 if strpos(QJH9,"Maintaining a strong dollar")~=0 & QJH9~="" 
label var QJH9_6 "Fed objective: Maintaining a strong dollar"

gen QJH9_7=0 if QJH9~=""
replace QJH9_7=1 if strpos(QJH9,"Reducing economic inequality")~=0 & QJH9~="" 
label var QJH9_7 "Fed objective: Reducing economic inequality"

gen QJH9_8=0 if QJH9~=""
replace QJH9_8=1 if strpos(QJH9,"Fighting climate change")~=0 & QJH9~="" 
label var QJH9_8 "Fed objective: Fighting climate change"

gen QJH9_9=0 if QJH9~=""
replace QJH9_9=1 if strpos(QJH9,"Mitigating the economic consequences of racism")~=0 & QJH9~="" 
label var QJH9_9 "Fed objective: Mitigating the economic consequences of racism"

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* QJH10

gen QJH10_1=0 if QJH10~=""
replace QJH10_1=1 if strpos(QJH10,"Keep the inflation rate as close as possible to a specific target at all times")~=0 & QJH10~="" 
label var QJH10_1 "Fed objective: Keep the inflation rate as close as possible to a specific target at all times"

gen QJH10_2=0 if QJH10~=""
replace QJH10_2=1 if strpos(QJH10,"Make inflation, on average, be approximately equal to a target rate")~=0 & QJH10~="" 
label var QJH10_2 "Fed objective: Make inflation, on average, be approximately equal to a target rate"

gen QJH10_3=0 if QJH10~=""
replace QJH10_3=1 if strpos(QJH10,"Keep prices from rising over time")~=0 & QJH10~="" 
label var QJH10_3 "Fed objective: Keep prices from rising over time"

gen QJH10_4=0 if QJH10~=""
replace QJH10_4=1 if strpos(QJH10,"Ensure inflation is sufficiently high to erode the value of government debt")~=0 & QJH10~="" 
label var QJH10_4 "Fed objective: Ensure inflation is sufficiently high to erode the value of government debt"

gen QJH10_5=0 if QJH10~=""
replace QJH10_5=1 if strpos(QJH10,"Keep the inflation rate low enough to promote a strong dollar")~=0 & QJH10~="" 
label var QJH10_5 "Fed objective: Keep the inflation rate low enough to promote a strong dollar"

gen QJH10_6=0 if QJH10~=""
replace QJH10_6=1 if strpos(QJH10,"None of the above")~=0 & QJH10~="" 
label var QJH10_6 "Fed objective: None of the above"

gen QJH10_7=0 if QJH10~=""
replace QJH10_7=1 if strpos(QJH10,"know")~=0 & QJH10~="" 
label var QJH10_7 "Fed objective: I don’t know"

gen QJH10_A=0
replace QJH10_A=1 if QJH10_6==1
replace QJH10_A=1 if QJH10_7==1
replace QJH10_A=1 if QJH10_6==.

foreach var in ///
	QJH10_1 QJH10_2 QJH10_3 QJH10_4 QJH10_5 QJH10_6 QJH10_7 QJH10_A /// What does Fed in terms of prices?
	{
	    replace `var'=0 if `var'==.
	}
	
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* QJH7_DO

gen QJH7_1=0 if QJH7~=""
replace QJH7_1=1 if strpos(QJH7,"There was an international meeting of central bankers")~=0 & QJH7~="" 
label var QJH7_1 "What heard about the Fed: There was an international meeting of central bankers"

gen QJH7_2=0 if QJH7~=""
replace QJH7_2=1 if strpos(QJH7,"There was a change in interest rates announced")~=0 & QJH7~="" 
label var QJH7_2 "What heard about the Fed: There was a change in interest rates announced "

gen QJH7_3=0 if QJH7~=""
replace QJH7_3=1 if strpos(QJH7,"There was a change in the leadership at the Federal Reserve")~=0 & QJH7~="" 
label var QJH7_3 "What heard about the Fed: There was a change in the leadership at the Federal Reserve"

gen QJH7_4=0 if QJH7~=""
replace QJH7_4=1 if strpos(QJH7,"There was an announcement about new strategies at the Federal Reserve")~=0 & QJH7~="" 
label var QJH7_4 "What heard about the Fed: There was an announcement about new strategies at the Federal Reserve"

gen QJH7_5=0 if QJH7~=""
replace QJH7_5=1 if strpos(QJH7,"The Federal Reserve put in place new lending facilities to fight the recession")~=0 & QJH7~="" 
label var QJH7_5 "What heard about the Fed: The Federal Reserve put in place new lending facilities to fight the recession"

gen QJH7_6=0 if QJH7~=""
replace QJH7_6=1 if strpos(QJH7,"remember")~=0 & QJH7~="" 
label var QJH7_6 "What heard about the Fed: I don’t remember"




*===============================================================================
*		label variables
*===============================================================================

label var StartDate "Start Date"
label var EndDate "End Date"
label var Durationinseconds "Duration (in seconds)"
label var LocationLatitude "Location Latitude"
label var LocationLongitude "Location Longitude"

label var Q1 "Please enter your age:"
label var Q2 "What is your level of English?"
label var Q3 "Please indicate your gender."
label var Q48 "What is the highest level of school you have completed, or the highest degree you have achieved?"
label var Q49 "Please indicate the range of your yearly net disposable income"
label var Q50 "What is the postal (zip) code for the address of your permanent residence?"

label var Q124 "50 States, D.C. and Puerto Rico"
label var Q51 "How would you identify your ethnicity? Please select all that apply."
label var Q52 "Do you consider yourself of Hispanic, Latino or Spanish origin?"

label var Q1341 "Over the next 12 months, do you think that there will be an increase or decrease in GDP?"
label var Q1342I "What do you expect the rate of increase in GDP to be over the next 12 months? I expect the rate of increase to be ___ percent over the next 12 months."
label var Q1342D "What do you expect the rate of decrease in GDP to be over the next 12 months? I expect the rate of decrease to be ___ percent over the next 12 months."

label var QA11 "In your view, will the total income of all members of your household (including you), after taxes and deductions, increase or decrease over the next 12 months?"
label var QA12I "By how much do you expect total income of all members of your household to increase over the next 12 months? Over the next 12 months, I expect total income of all members of my household to increase by ___ percent."
label var QA12D "By how much do you expect total income of all members of your household to decrease over the next 12 months? Over the next 12 months, I expect total income of all members of my household to decrease by ___ percent."

label var Q111 "The next few questions are about inflation. Over the next 12 months, do you think that there will be inflation or deflation?"
label var Q112I "What do you expect the rate of inflation to be over the next 12 months? I expect the rate of inflation to be ___ percent over the next 12 months."
label var Q112D "What do you expect the rate of deflation to be over the next 12 months? I expect the rate of deflation to be ___ percent over the next 12 months."


label var Q13_1 "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be 12% or higher"
label var Q13_2 "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 8% and 12%"
label var Q13_3 "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 4% and 8%"
label var Q13_4 "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 2% and 4%"
label var Q13_5 "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 0% and 2%"
label var Q13_6 "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 0% and 2%"
label var Q13_7 "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 2% and 4%"
label var Q13_8 "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 4% and 8%"
label var Q13_9 "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 8% and 12%"
label var Q13_10 "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be 12% or higher"


label var Q151 "Now we would like you to think about inflation further into the future. Over the 12-month period between September 2022 and September 2023 do you think that there will be inflation or deflation?"
label var Q152I "What do you expect the rate of inflation to be over the 12-month period between September 2022 and September 2023? I expect the rate of inflation to be ___ percent."
label var Q152D "What do you expect the rate of deflation to be over the 12-month period between September 2022 and September 2023? I expect the rate of deflation to be ___ percent."

label var QJH1 "How do you usually get news about the economy?  Select all that apply. - Selected Choice"
label var QJH1_10_TEXT "How do you usually get news about the economy?  Select all that apply. - Another source: - Text"
label var QJH1_DO "How do you usually get news about the economy?  Select all that apply. - Display Order"

label var QJH2 "How often do you get news about the economy? - Selected Choice"
label var QJH2_8_TEXT "How often do you get news about the economy? - Other: - Text"

label var QJH3 "Have you heard any news about monetary policy or the Federal Reserve in the last week?"
label var QJH4 "About how many news articles, TV or radio reports, or other pieces of news about monetary policy or the Federal Reserve did you read or hear in the last week?"

label var QJH5 "Where did you hear this news about monetary policy or the Federal Reserve?  Select all that apply. - Selected Choice"
label var QJH5_9_TEXT "Where did you hear this news about monetary policy or the Federal Reserve? Select all that apply. - Another source: - Text"
label var QJH5_DO "Where did you hear this news about monetary policy or the Federal Reserve?  Select all that apply. - Display Order"

label var QJH6 "When did you hear the most recent news about monetary policy or the Federal Reserve? Please select the most appropriate answer."

label var QJH7 "What were the main pieces of news about monetary policy or the Federal Reserve that you heard most recently?  Select all that apply. - Selected Choice"
label var QJH7_6_TEXT "What were the main pieces of news about monetary policy or the Federal Reserve that you heard most recently?  Select all that apply. - Other: - Text"
label var QJH7_DO "What were the main pieces of news about monetary policy or the Federal Reserve that you heard most recently?  Select all that apply. - Display Order"

label var QJH8 "Who did you hear news about? Select all that apply."
label var QJH8_DO "Who did you hear news about? Select all that apply. - Display Order"

label var QJH9 "In terms of the Federal Reserves broad economic objectives, what do you think it views as most important among the following?  Please select up to 2."
label var QJH9_DO "In terms of the Federal Reserves broad economic objectives, what do you think it views as most important among the following?  Please select up to 2. - Display Order"

label var QJH10 "In terms of prices in the economy, which do you think best represents what the Federal Reserve is trying to do?  Select all that apply."
label var QJH10_DO "In terms of prices in the economy, which do you think best represents what the Federal Reserve is trying to do?  Select all that apply. - Display Order"

label var QJH11 "What rate of inflation do you think the Federal Reserve tries to achieve in the longer run?______% per year"

label var QJH121 "Suppose that the inflation rate in 2021 turns out to be around 1%. What inflation rate do you think the Federal Reserve will try to achieve over the following year or two?_____ % per year"
label var QJH122 "Suppose that the inflation rate in 2021 turns out to be around 3%. What inflation rate do you think the Federal Reserve will try to achieve over the following year or two?_____ % per year"

label var QJH13 "Over the next 5 years, do you think there will be inflation or deflation on average?"
label var QJH13a "What do you expect the average annual rate of inflation to be over the next 5 years? I expect the average annual rate of inflation to be ___ percent per year over the next 5 years."
label var QJH13b "What do you expect the average annual rate of deflation to be over the next 5 years? I expect the average annual rate of deflation to be ___ percent per year over the next 5 years."

label var QJH14 "Over the next 5 years, do you think that there will be an increase or decrease in GDP on average?"
label var QJH14a "What do you expect the average annual rate of increase in GDP will be over the next 5 years? increase to be ___ percent per year over the next 5 years."
label var QJH14b "What do you expect the average annual rate of decrease in GDP will be over the next 5 years? decrease to be ___ percent per year over the next 5 years."

label var QJH15 "In your view, will the total income of all members of your household (including you), after taxes and deductions, increase or decrease over the next 5 years on average?"
label var QJH15a "What do you expect the average annual rate of increase in the total income of all members of your household will be over the next 5 years?  ave annual increase ___ percent per year over the next 5 years."
label var QJH15b "What do you expect the average annual rate of decrease in the total income of all members of your household will be over the next 5 years?  ave annual decrease ___ percent per year over the next 5 years."

label var QJH16 "When do you expect that mortgage rates will start to rise in a significant way?"
label var QJH17_1 "How would you rate the credibility of the Federal Reserve in terms of its ability to achieve maximum employment and stable prices? - Rating"
label var QJH18_1 "What do you think is the chance that inflation will be more than 5% in the next 12 months? - Probability"

label var Q27 "Which fraction of your income do you invest?"
label var Q53 "What is your civil status?"
label var Q121 "What would you say is your political affiliation?"
label var Q54 "How many children do you have?"
label var Q55 "What is the percent chance that you will leave any inheritance?"
label var FL_5_DO "FL_5 - Block Randomizer - Display Order"
label var FL_37_DO "FL_37 - Block Randomizer - Display Order"
label var FL_38_DO "FL_38 - Block Randomizer - Display Order"

label var FL_37_DO "Randomize over what people see: 1% or 3% inflation in the Fed reaction"

*===============================================================================
*			construct variables: implied mean and uncertainty
*===============================================================================

gen epi_12m_12plus= Q13_1 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be 12% or higher" */
gen epi_12m_8_12= Q13_2 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 8% and 12%" */
gen epi_12m_4_8= Q13_3 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 4% and 8%" */
gen epi_12m_2_4= Q13_4 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 2% and 4%" */
gen epi_12m_0_2=  Q13_5 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 0% and 2%" */
gen epi_12m_m2_0= Q13_6 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 0% and 2%" */
gen epi_12m_m4_m2= Q13_7 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 2% and 4%" */
gen epi_12m_m8_m4= Q13_8 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 4% and 8%" */
gen epi_12m_m12_m8= Q13_9 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 8% and 12%" */
gen epi_12m_m12minus = Q13_10 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be 12% or higher" */


*generate average				
gen epi_12m_mean = 	epi_12m_12plus*14 + ///
					epi_12m_8_12*10 + ///
					epi_12m_4_8*6 + ///
					epi_12m_2_4*3 + ///
					epi_12m_0_2*1 + ///
					epi_12m_m2_0*(-1) + ///
					epi_12m_m4_m2*(-3) + ///
					epi_12m_m8_m4*(-6) + ///
					epi_12m_m12_m8*(-10) + ///
					epi_12m_m12minus*(-14)

replace epi_12m_mean=epi_12m_mean/100

*generate individual variance					
gen epi_12m_var	 =  epi_12m_12plus*(14-epi_12m_mean)^2 + ///
					epi_12m_8_12*(10-epi_12m_mean)^2 + ///
					epi_12m_4_8*(6-epi_12m_mean)^2 + ///
					epi_12m_2_4*(3-epi_12m_mean)^2 + ///
					epi_12m_0_2*(1-epi_12m_mean)^2 + ///
					epi_12m_m2_0*(-1-epi_12m_mean)^2 + ///
					epi_12m_m4_m2*(-3-epi_12m_mean)^2 + ///
					epi_12m_m8_m4*(-6-epi_12m_mean)^2 + ///
					epi_12m_m12_m8*(-10-epi_12m_mean)^2 + ///
					epi_12m_m12minus*(-14-epi_12m_mean)^2
										
replace epi_12m_var=epi_12m_var/100					

*generate individual sd
gen epi_12m_std=epi_12m_var^0.5


*===============================================================================
*			construct variables: point predictions
*===============================================================================

gen egdp_12m=.
replace egdp_12m=abs(Q1342I) if Q1341==2
replace egdp_12m=-abs(Q1342D) if Q1341==1
label var egdp_12m "Over the next 12 months, do you think that there will be an increase or decrease in GDP?"
replace egdp_12m=100 if egdp_12m>100 & egdp_12m~=.
replace egdp_12m=-100 if egdp_12m<-100 & egdp_12m~=.


gen edy_12m=.
replace edy_12m=abs(QA12I) if QA11==2
replace edy_12m=-abs(QA12D) if QA11==1
label var edy_12m "will the total income of all members of your household (including you), after taxes and deductions, increase or decrease over the next 12 months?"
replace edy_12m=100 if edy_12m>100 & edy_12m~=.
replace edy_12m=-100 if edy_12m<-100 & edy_12m~=.


gen epi_12m=.
replace epi_12m=abs(Q112I) if Q111==2
replace epi_12m=-abs(Q112D) if Q111==1
label var epi_12m "Over the next 12 months, do you think that there will be inflation or deflation?"
replace epi_12m=100 if epi_12m>100 & epi_12m~=.
replace epi_12m=-100 if epi_12m<-100 & epi_12m~=.


gen egdp_5y=.
replace egdp_5y=abs(QJH14a) if QJH14==2
replace egdp_5y=-abs(QJH14b) if QJH14==1
label var egdp_5y "Over the next 5 years, do you think that there will be an increase or decrease in GDP?"
replace egdp_5y=100 if egdp_5y>100 & egdp_5y~=.
replace egdp_5y=-100 if egdp_5y<-100 & egdp_5y~=.


gen edy_5y=.
replace edy_5y=abs(QJH15a) if QJH15==2
replace edy_5y=-abs(QJH15b) if QJH15==1
label var edy_5y "will the total income of all members of your household (including you), after taxes and deductions, increase or decrease over the next 5 years?"
replace edy_5y=100 if edy_5y>100 & edy_5y~=.
replace edy_5y=-100 if edy_5y<-100 & edy_5y~=.


gen epi_5y=.
replace epi_5y=abs(QJH13a) if QJH13==2
replace epi_5y=-abs(QJH13b) if QJH13==1
label var epi_5y "Over the next 5 years, do you think that there will be inflation or deflation?"
replace epi_5y=100 if epi_5y>100 & epi_5y~=.
replace epi_5y=-100 if epi_5y<-100 & epi_5y~=.

*===============================================================================
*		treatment variables
*===============================================================================

gen treatment_control=(FL_38_DO==1)
gen treatment_IT=(FL_38_DO==2)
gen treatment_AIT=(FL_38_DO==3)

gen treatmentN=1 if (FL_38_DO==1)
replace treatmentN=2 if (FL_38_DO==2)
replace treatmentN=3 if (FL_38_DO==3)

*===============================================================================
*		clean variabes
*===============================================================================

*** zip code instead of age
replace Q1=. if Q1>100 & Q1~=.
rename Q1 age

*** sequential dates (Sept is 31 + day)
gen start_day1=start_day
replace start_day1=32 if start_day==1

*** number of children
replace Q54=5 if Q54>5 & Q54~=.

gen N_children=Q54
gen male=(Q3==2)
gen Native_English=(Q2==3)
gen educ=Q48
gen income=Q49
gen nonwhite=(Q51~=15)
gen hispanic=(Q52==2)
gen married=(Q53==2)
gen single=(Q53==5)

gen party_democrat=(Q121==1)
gen party_republican=(Q121==4)
gen party_other=(Q121==3)


*===============================================================================
*		add weights
*===============================================================================
cd "C:\Dropbox\Average_target_survey\replication_folder\rawdata"
duplicates report StartDate EndDate LocationLatitude LocationLongitude
joinby StartDate EndDate LocationLatitude LocationLongitude using combined_data_with_weights, unmatched(both)
tab _merge
duplicates report StartDate EndDate LocationLatitude LocationLongitude

drop _merge

cd "C:\Dropbox\Average_target_survey\replication_folder\workfiles"

joinby StartDate EndDate LocationLatitude LocationLongitude using step002, unmatched(both)
tab _merge
duplicates report StartDate EndDate LocationLatitude LocationLongitude

drop _merge

compress
save step001, replace






